package main
import(
	"fmt"
	"os"
	"io"
	"io/ioutil"
)
func CopyFile(destFileName string,srcFileName string)(err error){
	srcfile,err1:=os.Open(srcFileName)
	defer srcfile.Close()
	if err1!=nil{
		fmt.Println("open src file fail, err=",err1)
		return err1
	}
	destfile,err2:=os.OpenFile(destFileName,os.O_CREATE|os.O_WRONLY,0666)
	defer destfile.Close()
	if err2!=nil{
		fmt.Println("open dest file fail,err=",err2)
		return err2
	}
	sliceTemp:=make([]byte,120)
	for{
		n,err:=srcfile.Read(sliceTemp)
		if err==io.EOF{
			fmt.Println("copy over!")
			break
		}
		if err!=nil{
			fmt.Println("read file fail err=",err)
			return err
		}
		_,err2:=destfile.Write(sliceTemp[:n])
		if err!=nil{
			fmt.Println("write file fail err=",err)
			return err2
		}
	}
	return nil
}
func copyFile1(destFileName string,srcFileName string)(err error){

	slice,err:=ioutil.ReadFile(srcFileName)
	if err!=nil{
		fmt.Println("ReadFile fail,err=",err)
		return err
	}
	err=ioutil.WriteFile(destFileName,slice,0666)
	if err!=nil{
		fmt.Println("WriteFile err")
		return err
	}
	return nil
}
func main(){
	// srcFileName:="../file_dir01/test.txt"
	// destFileName:="./test1.txt"
	// err:=CopyFile(destFileName,srcFileName)
	// if err!=nil{
	// 	fmt.Println("copy file fail err=",err)
	// }
	// err:=copyFile1(destFileName,srcFileName)
	// if err!=nil{
	// 	fmt.Println("copyfile err")
	// }
	os.Mkdir("aaa",0666)
	os.Remove("./bbb")
	// err:=os.MkdirAll("./bbb/ccc/ddd",0666)
	// if err!=nil{
	// 	fmt.Println(err)
	// }
	os.RemoveAll("./bbb/ccc/ddd")
	os.Rename("./test.txt","./test11.txt")
}